﻿using System;
using AMM.Business;
using AMM.Model;
using AMM.Model.Business;

namespace AMM.UserControls {
    public partial class CustomerOrderSearchControl : BaseSearchControl {

        public override BaseSearchModel GetSearchModel() {
            int currencyValue = Convert.ToInt32(this.cmbCurrency.SelectedValue);
            int paymentTypeValue = Convert.ToInt32(this.cmbPaymentType.SelectedValue);
            int orderTypeValue = Convert.ToInt32(this.cmbOrderType.SelectedValue);

            CustomerOrderSearchModel searchResult = new CustomerOrderSearchModel();
            searchResult.OrderNo = this.tbOrderNo.Text;
            searchResult.CustomerCode = this.tbCode.Text;
            searchResult.CustomerName = this.tbName.Text;
            searchResult.OrderDateStart = this.GetDateTimePickerValue(this.dtpOrderStart);
            searchResult.OrderDateEnd = this.GetDateTimePickerValue(this.dtpOrderEnd);
            searchResult.DeliverDateStart = this.GetDateTimePickerValue(this.dtpDeliverStart);
            searchResult.DeliverDateEnd = this.GetDateTimePickerValue(this.dtpDeliverEnd);
            searchResult.PayCurrencyId = currencyValue;
            searchResult.PaymentTypeId = paymentTypeValue;
            searchResult.OrderTypeId = orderTypeValue;

            if (currencyValue == 0) { searchResult.PayCurrencyId = null; }
            if (paymentTypeValue == 0) { searchResult.PaymentTypeId = null; }
            if (orderTypeValue == 0) { searchResult.OrderTypeId = null; }

            return searchResult;
        }

        public override void ResetSearchModel() {
            this.tbOrderNo.Clear();
            this.tbCode.Clear();
            this.tbName.Clear();
            this.dtpOrderStart.Checked = false;
            this.dtpOrderEnd.Checked = false;
            this.dtpDeliverStart.Checked = false;
            this.dtpDeliverEnd.Checked = false;
            this.cmbCurrency.SelectedIndex = 0;
            this.cmbPaymentType.SelectedValue = 0;
            this.cmbOrderType.SelectedValue = 0;
        }

        public CustomerOrderSearchControl() {
            this.InitializeComponent();

            this.BindBasics(this.cmbCurrency, BasicsType.Currency);
            this.BindBasics(this.cmbPaymentType, BasicsType.PaymentType);
            this.BindBasics(this.cmbOrderType, BasicsType.OrderType);
        }
    }
}
